﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using MLSMooc.BO;
using MLSMooc.Helper;
using Dapper;
using MLSMooc.DAO.Interface.Book;

namespace MLSMooc.DAO.Implement.Book
{
   public class BookDAO :IBookDAO
    {
        private static BookDAO instance = new BookDAO();
        private BookDAO() { }
        public static BookDAO Getinstance() => instance;

        private static readonly string queryField = "select * from Mooc_Course_Books where isDelete=0";

        public async Task<IEnumerable<BookBO>> GetByIdBookInfo(string id)
        {
            using (SqlConnection conn=new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                sql.Append($@" and Id in("+id+")");
                var res = await conn.QueryAsync<BookBO>(sql.ToString());
                return res;
            }
        }

        public async Task<IEnumerable<BookBO>> GetBookAllList()
        {
            using (SqlConnection conn = new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                var res = await conn.QueryAsync<BookBO>(sql.ToString());
                return res;
            }
        }
    }
}
